﻿Imports System.ComponentModel

''' <summary>
''' 值对
''' </summary>
Public Class PairValue
    Implements INotifyPropertyChanged

    ''' <summary>
    ''' 源值
    ''' </summary>
    Public ReadOnly Origin As Integer

    Sub New(ByVal Origin As Integer, ByVal Value As Double)
        Me.Origin = Origin
        Me.Value = Value
    End Sub

    Sub New(ByVal Origin As Integer)
        Me.New(Origin, Origin)
    End Sub

    Public Event PropertyChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged

    ''' <summary>
    ''' 当前值
    ''' </summary>
    Property Value As Double
        Get
            Return mValue
        End Get
        Set(ByVal value As Double)
            Select Case value
                Case Is > Origin
                    mValue = Origin
                Case Is < 0
                    mValue = 0
                Case Else
                    mValue = value
            End Select
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(Nothing))
        End Set
    End Property
    Private mValue As Double

    ''' <summary>
    ''' 用于显示的值
    ''' </summary>
    ReadOnly Property ShowValue As Integer
        Get
            Return Math.Ceiling(Value)
        End Get
    End Property

    ''' <summary>
    ''' 显示百分比
    ''' </summary>
    ReadOnly Property Percentage As Double
        Get
            If Origin <> 0 Then
                Return Value / Origin
            End If
            Return 0
        End Get
    End Property

    Public Overrides Function ToString() As String
        Return Value.ToString
    End Function

End Class
